package com.cloud.wms.http.url;

import android.text.TextUtils;

import com.cloud.wms.BuildConfig;
import com.cloud.wms.app.FineExApplication;

import okhttp3.Request;


/**
 * @Author： Chen
 * @Date： 2020/3/20
 * @Desc： 站点地址管理
 */
public class SiteManager {
    //临时请求地址
    private static final String LS_SM_URL = "http://172.16.100.20:8025/";
    //临时请求地址
    private static final String LS_TM_URL = "http://172.16.100.20:8025/";
    //临时请求地址
    private static final String LS_WMS_URL = "http://172.16.100.20:8025/";
    //临时请求地址
    private static final String LS_WES_IN_URL = "http://172.16.100.20:8025/";
    //临时请求地址
    private static final String LS_WES_INTERNAL_URL = "http://172.16.100.20:8025/";
    //临时请求地址
    private static final String LS_WES_GROUP_URL = "http://172.16.100.20:8025/";
    //临时请求地址
    private static final String LS_WES_BATCH = "http://172.16.100.20:8025/";
    //临时请求地址
    private static final String LS_WES_SORT = "http://172.16.100.20:8025/";

    private static final boolean IS_TEMPORARY_URL = false;

    /**
     * 获取站点对应地址
     *
     * @param nameEnum
     * @return
     */
    public static String getBaseUrl(SiteNameEnum nameEnum) {
        if (BuildConfig.DEBUG && IS_TEMPORARY_URL) {
            switch (nameEnum) {
                case SM:
                    return LS_SM_URL;
                case TM:
                    return LS_TM_URL;
                case WMS:
                    return LS_WMS_URL;
                case WES_IN:
                    return LS_WES_IN_URL;
                case WES_INTERNAL:
                    return LS_WES_INTERNAL_URL;
                case WES_GROUP:
                    return LS_WES_GROUP_URL;
                case WES_BATCH:
                    return LS_WES_BATCH;
                case WES_SORT:
                    return LS_WES_SORT;
            }
            return LS_WMS_URL;
        } else {
            switch (nameEnum) {
                case SM:
                    return BuildConfig.BASE_SM_URL;
                case TM:
                    return BuildConfig.BASE_TM_URL;
                case WMS:
                    return BuildConfig.BASE_WMS_URL;
                case WES_IN:
                    return BuildConfig.BASE_WES_IN_URL;
                case WES_INTERNAL:
                    return BuildConfig.BASE_WES_INTERNAL_URL;
                case WES_BATCH:
                    return BuildConfig.BASE_WES_BATCH;
                case WES_SORT:
                    return BuildConfig.BASE_WES_SORT;
                case WES_GROUP:
                    return BuildConfig.BASE_WES_GROUP_URL;
            }
            return BuildConfig.BASE_WMS_URL;
        }
    }

    public static String getBaseUrl() {
        if (BuildConfig.DEBUG && IS_TEMPORARY_URL) {
            return LS_WMS_URL;
        } else {
            return BuildConfig.BASE_WMS_URL;
        }
    }

    /**
     * 获取站点签名请求头
     *
     * @param origin
     * @return
     */
    public static Request getSignHeader(Request origin) {
        Request.Builder builder = origin
                .newBuilder()
                .header("device", "2");
        if (!TextUtils.isEmpty(FineExApplication.component().loginCache().getToken())) {
            builder.header("Authorization", FineExApplication.component().loginCache().getToken());
        }
        return builder.build();
    }

    public static final String UPDATE_VERSION_URL = BuildConfig.UPDATE_URL + "UpdateService.asmx/GetNewVersion";        //获取更新URL

    public static final String UPDATE_VERSION_URL_SPARE = BuildConfig.UPDATE_URL + "UpdateService.asmx/GetNewVersion";   //获取更新URL(备用地址)

    public static final String UPDATE_SYS = "CWMSApp";                                                                //获取版本更新系统类型

    public static final String DOWNLOAD_BASE_URL = BuildConfig.UPDATE_URL + "UpdateFiles/CWMSApp";                     //下载apkURL前缀

    public static final String DOWNLOAD_BASE_URL_SPARE = BuildConfig.UPDATE_URL + "UpdateFiles/CWMSApp";                     //下载apkURL前缀(备用地址)
}
